package nu.aing.P20140811;

import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;

/**
 * @author memekmaut@gmail.com
 */
public class BubbleSortWithReversals {
    
    public static void main(String[] args) {
        BubbleSortWithReversals obj = new BubbleSortWithReversals();
        System.out.println(obj.getMinSwaps(
                new int[] {6,8,8,7,7},
                1
        ));
    }
    
    public int getMinSwaps(int[] A, int K) {
        
        Map<Integer, Integer> map = new LinkedHashMap<Integer, Integer>();
        int lowest = 0, biggest = 0;
        for(int i = 0; i < A.length; i++) {
            if(lowest == 0 || lowest > A[i]) {
                lowest = A[i];
            }
            if(biggest == 0 || biggest < A[i]) {
                biggest = A[i];
            }
            
            if(map.containsKey(A[i]) ) {
                map.put(A[i], map.get(A[i]) + 1);
            }
            else {
                map.put(A[i], 1);
            }
        }
        
        return getSortCount(A);
    }
    
    private int getSortCount(int[] A) {
        int count = 0;
        for(int i = 0; i < A.length; i++) {
            for(int j = i+1; j < A.length; j++) {
                if(A[i] > A[j]) {
                    int x = A[i];
                    A[i] = A[j];
                    A[j] = x;
                    count++;
                }
            }
        }
        return count;
    }
}
